﻿using System;
using System.Data;


public partial class manager_task_NewDefault : System.Web.UI.Page
{
    DBHelper db = new DBHelper();
    public string userbh;
    public string Html_Dept = "";
    public string Html_Dept_Detail = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bindData();
            GetDept();
            loadData();
        }
    }


    private void GetDept()
    {
        int i = 0;
        Html_Dept = "";
        DataTable dt = db.getList("select * from dict_dept where [isUsing]=1 order by id");
        foreach (DataRow dr in dt.Rows)
        {
            if (i == 0)
            {
                Html_Dept += "<li  role=\"presentation\" class=\"active\"><a href=\"#dept_" + dr["id"].ToString() + "\" role=\"tab\" data-toggle=\"tab\">" + dr["mc"].ToString() + "</a></li>";
            }
            else
            {
                Html_Dept += "<li role=\"presentation\"><a href=\"#dept_" + dr["id"].ToString() + "\" role=\"tab\" data-toggle=\"tab\">" + dr["mc"].ToString() + "</a></li>";
            }
            i = 1;
        }
    }

    private void loadData()
    {
        dept_id.Value = "";
        int i = 0;
        DataTable dt = db.getList("select * from dict_dept where [isUsing]=1 order by id");
        foreach (DataRow dr in dt.Rows)
        {
            dept_id.Value = dept_id.Value + "|" + dr["id"].ToString();
            if (i == 0)
            { Html_Dept_Detail += "<div role=\"tabpanel\" class=\"tab-pane active\" id=\"dept_" + dr["id"].ToString() + "\">"; }
            else
            { Html_Dept_Detail += "<div role=\"tabpanel\" class=\"tab-pane\" id=\"dept_" + dr["id"].ToString() + "\">"; }

            Html_Dept_Detail += "<div class=\"box-body\">";
            Html_Dept_Detail += "<table id=\"table_" + dr["id"].ToString() + "\" class=\"table table-bordered table-striped\">";
            Html_Dept_Detail += "<thead>";
            Html_Dept_Detail += "<tr>";
            Html_Dept_Detail += "<th></th>";
            Html_Dept_Detail += "<th class=\"col-sm-7\">名称</th>";
            Html_Dept_Detail += "<th class=\"col-sm-2\">类型</th>";
            Html_Dept_Detail += "<th class=\"col-sm-3\">当前在岗</th>";
            Html_Dept_Detail += "</tr>";
            Html_Dept_Detail += "</thead>";
            Html_Dept_Detail += "<tbody>";
            DataTable dt1 = db.getList("v_dict_dept_position", "*", "dept=" + dr["id"].ToString() + " and type<>1", "bh");
            foreach (DataRow dr1 in dt1.Rows)
            {
                Html_Dept_Detail += "<asp:Repeater runat=\"server\">";
                Html_Dept_Detail += "<ItemTemplate>";
                Html_Dept_Detail += "<tr style=\"cursor:pointer\" onclick=\"SetZxGw('" + dr1["id"].ToString() + "','" + dr1["mc"].ToString() + "|" + dr1["userName"].ToString() + "','"+ dr1["type"].ToString()+"')\">";
                Html_Dept_Detail += "<td>" + dr1["id"].ToString() + "</td>";
                switch (dr1["type"].ToString())
                {
                    case "1":
                        Html_Dept_Detail += "<td><b>" + dr1["mc"].ToString() + "</b></td>";
                        Html_Dept_Detail += "<td>" + SQ_Eval_Pub.GetPsType(dr1["type"].ToString()) + "</td>";
                        break;
                    case "2":
                        Html_Dept_Detail += "<td style=\"padding-left:30px;\">" + dr1["mc"].ToString() + "</td>";
                        Html_Dept_Detail += "<td style=\"padding-left:15px;\">" + SQ_Eval_Pub.GetPsType(dr1["type"].ToString()) + "</td>";
                        break;
                    case "3":
                        Html_Dept_Detail += "<td style=\"padding-left:50px;\">" + dr1["mc"].ToString() + "</td>";
                        Html_Dept_Detail += "<td style=\"padding-left:25px;\">" + SQ_Eval_Pub.GetPsType(dr1["type"].ToString()) + "</td>";
                        break;
                }
                Html_Dept_Detail += "<td><b>" + dr1["userName"].ToString() + "</b></td>";
                Html_Dept_Detail += "</tr>";
            }
            Html_Dept_Detail += "</tbody>";
            Html_Dept_Detail += "</table>";
            Html_Dept_Detail += "</div>";
            Html_Dept_Detail += "</div>";
            i = 1;
        }
    }
    private void bindData()
    {
        userbh = Session[AppConfig.SESSION_USER_BH].ToString();
        DataTable dt = db.getList("select * from v_A_Task where cz_userbh='" + userbh + "'");
        rptDeApply_1.DataSource = dt;
        rptDeApply_1.DataBind();

    }

    protected void btnGet_Click(object sender, EventArgs e)
    {
        string hid = hidBID.Value;
        string sql = "select* from dict_dept_position_evaluate where id=" + hid;
        DataTable dt = db.getList(sql);
        if (dt.Rows.Count > 0)
        {
            DataRow dr = dt.Rows[0];
            txt_mc.Text = dr["mc"].ToString();
            dllType.SelectedValue = dr["type"].ToString();
            string isusstr = "0";
            if (dr["isUsing"].ToString() == "True")
            {
                isusstr = "1";
            }
            ddlIsUsing.SelectedValue = isusstr;
        }
    }


}